package com.xmsx.back.service.admin;

import com.xmsx.back.mapper.admin.OrganizationMapper;
import com.xmsx.back.pojo.Organization;
import com.xmsx.back.pojo.Recruitment;
import com.xmsx.back.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrganizationService {
    @Autowired
    OrganizationMapper organizationMapper;

    /**
     * 获取某个单位信息的所有数据
     *
     * @param id
     * @return
     */
    public Organization getById(int id) {
        return organizationMapper.getById(id);
    }

    /**
     * 插入单位信息
     *
     * @param organization
     */
    public void setOrganization(Organization organization) {
        organizationMapper.setOrganization(organization);
    }

    /**
     * 修改单位信息
     *
     * @param organization
     */
    public void updateOrganization(Organization organization) {
        organizationMapper.updateOrganization(organization);
    }

    /**
     * 删除单位信息
     *
     * @param id
     */
    public void deleteOrganization(int id) {
        organizationMapper.deleteOrganization(id);
    }

    /**
     * 分页查找多条数据
     *
     * @param page
     * @param size
     * @return
     */
    public Pager<Organization> findByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        Pager<Organization> pager = new Pager<Organization>();
        List<Organization> list = organizationMapper.findByPager(params);
        pager.setRows(list);
        pager.setTotal(organizationMapper.count());
        return pager;
    }

    /**
     * 按关键词分页查找多条数据
     *
     * @param page
     * @param size
     * @param keyword
     * @return
     */
    public Pager<Organization> findByKeywordByPager(int page, int size, String keyword) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        params.put("keyword", keyword);
        Pager<Organization> pager = new Pager<Organization>();
        List<Organization> list = organizationMapper.findByKeywordByPager(params);
        pager.setRows(list);
        pager.setTotal(organizationMapper.countByKeyword(keyword));
        return pager;
    }
}
